package edu.core.testapp.shared;

public final class ChainAction implements Action {
	
	private Action toExecute;
	private Action toExecuteOnSuccess;
	private Action toExecuteOnFailure;
	
	public ChainAction(Action toExecute, Action toOnSuccess, Action ToOnFailure) {
		this.toExecute = toExecute;
		this.toExecuteOnSuccess = toOnSuccess;
		this.toExecuteOnFailure = ToOnFailure;
	}

	@Override
	public boolean execute() {
		return toExecute.execute();
	}
	
	protected final boolean onSuccess() {
		if (toExecuteOnSuccess != null)
			return toExecuteOnSuccess.execute();
		else
			return false;
	}
	
	protected final boolean onFaileure() {
		if (toExecuteOnFailure != null)
			return toExecuteOnFailure.execute();
		else
			return false;
	}

}
